package com.jianjun.common.util;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jfinal.json.Jackson;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;

/**
 * @author huangxiang
 * {@code @date} 2017/6/7
 */
@UtilityClass
public class UtilJackson {

    @SneakyThrows
    public static <T> T parse(String jsonStr, TypeReference<T> typeReference) {
        ObjectMapper objectMapper = Jackson.getJson().getObjectMapper();
        return objectMapper.readValue(removeExp(jsonStr), typeReference);
    }

    /**
     * 反序列化去除字符串异常字符
     */
    public static String removeExp(String json) {
        return json.replaceAll("(?<=[0-9])[LD](?=\\s|}|,)", "");
    }
}
